package de.slothsoft.wasbinich.core;

import java.util.Locale;

public final class WebserviceUrls {

    private static final String PRODUCTIVE_BASE_URL = "http://api.wasbinich-game.de/"; //$NON-NLS-1$
    private static final String DEBUG_BASE_URL = "http://189918.test-my-website.de/wasbinich/"; //$NON-NLS-1$
    public static final String BASE_URL = WasBinIch.DEBUG ? DEBUG_BASE_URL : PRODUCTIVE_BASE_URL;
    public static final String WEBSERVICE_URL = BASE_URL + "v1/"; //$NON-NLS-1$

    public static String getApplicationInfoUrl() {
	return getLocalizedUrl("application/info"); //$NON-NLS-1$
    }

    public static String getRandomPictureUrl() {
	return getLocalizedUrl("picture/random/"); //$NON-NLS-1$
    }

    public static String getManagerPicturesUrl() {
	return getStandardUrl("manager/pictures/"); //$NON-NLS-1$
    }

    public static String getManagerPictureByIdUrl(long id) {
	return getStandardUrl("manager/picture/get/" + id); //$NON-NLS-1$
    }

    public static String getManagerPictureCreateUrl() {
	return getStandardUrl("manager/picture/create"); //$NON-NLS-1$
    }

    public static String getManagerPictureUpdateUrl() {
	return getStandardUrl("manager/picture/update"); //$NON-NLS-1$
    }

    public static String getManagerPictureDeleteUrl(long id) {
	return getStandardUrl("manager/picture/delete/" + id); //$NON-NLS-1$
    }

    private static String getLocalizedUrl(String relativeUrl) {
	String language = Locale.getDefault().getLanguage();
	if (language.equals("")) { //$NON-NLS-1$
	    System.err.println("Language is NULL! Using EN!"); //$NON-NLS-1$
	    language = "en"; //$NON-NLS-1$
	}
	return WEBSERVICE_URL + language + "/" + relativeUrl; //$NON-NLS-1$
    }

    private static String getStandardUrl(String relativeUrl) {
	return WEBSERVICE_URL + relativeUrl;
    }

    private WebserviceUrls() {
	// hide me
    }
}
